package com.mywork.activity;

import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;

import com.ciko.code.adapter.WorkManagerBaodangListAdapter;
import com.ciko.code.base.BaseListActivity;
import com.ciko.code.bean.SelPolicyCountListEty;
import com.ciko.code.bean.SelPolicyListEty;
import com.ciko.code.http.BaseResponse;
import com.ciko.code.http.Req.SelPolicyListReq;
import com.mywork.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by ciko on 2015/12/6.
 */
public class WorkManagerCompanyDetailActivity extends BaseListActivity {

    private SelPolicyCountListEty selPolicyCountListEty;

    private WorkManagerBaodangListAdapter workManagerBaodangListAdapter;

    private List<SelPolicyListEty> selPolicyListEtyListPerson = new ArrayList<>();



    @Override
    protected void initTopBar() {

        selPolicyCountListEty = (SelPolicyCountListEty) getIntent().getSerializableExtra("SelPolicyCountListEty");
        setTitle(selPolicyCountListEty.getHolderName());
        enableNavLeftImg();
        setHeaderView(R.layout.layout_work_manager_title);
    }

    @Override
    protected void initAdapter() {
        workManagerBaodangListAdapter = new WorkManagerBaodangListAdapter(this, selPolicyListEtyListPerson, R.layout.item_list_work_manager_baodang_company);
        setAdapter(workManagerBaodangListAdapter);
    }

    @Override
    protected void initDates() {
        doRequestHttp(new SelPolicyListReq(0, 10, null,null));
    }

    @Override
    protected void initListener() {

    }

    @Override
    public void onResponseSuccess(BaseResponse<?> response, String tag) {
        super.onResponseSuccess(response, tag);

        List<SelPolicyListEty> selPolicyListEtyListPersonResult = (List<SelPolicyListEty>) response.getReturnObject();

        for (SelPolicyListEty selPolicyListEty : selPolicyListEtyListPersonResult){
            if(selPolicyListEty.getHolderName().equals(selPolicyCountListEty.getHolderName())){
                selPolicyListEtyListPerson.add(selPolicyListEty);
            }
        }

        notifyDataSetChanged();

    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        super.onItemClick(parent, view, position, id);

        SelPolicyListEty selPolicyListEty = (SelPolicyListEty) parent.getAdapter().getItem(position);

        Intent intent = new Intent(this, WorkOrderDetailActivity.class);
        intent.putExtra("SelPolicyListEty", selPolicyListEty);
        startActivity(intent);

    }
}
